package com.henu.xyh.fragmentofXYH;


import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.henu.R;
import com.henu.xyh.MycollectActivity;
import com.henu.xyh.MyexpressActivity;
import com.henu.xyh.MyinformationActivity;
import com.henu.yizhiya.entity.Person;
import com.henu.zmb.UserGoods_MainActivity;
import com.henu.zmb.UserLoseGoods_MainActivity;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import cn.bmob.v3.BmobUser;

/**
 * A simple {@link Fragment} subclass.
 */
public class Mine extends Fragment {

    public Mine() {

    }
    private LinearLayout my_information;
    private LinearLayout my_allcollect;
    private LinearLayout my_allexpress;
    private LinearLayout my_alllose;
    private LinearLayout my_secondhand;
    private ImageView my_iv_image;
    private TextView my_name;
    private TextView my_identification;
    private Person p;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_fragment3,null);
        my_name= (TextView) view.findViewById(R.id.my_name);
        my_identification= (TextView) view.findViewById(R.id.my_identification);
        my_iv_image= (ImageView) view.findViewById(R.id.my_iv_image);
        my_information= (LinearLayout) view.findViewById(R.id.my_information);
        my_information.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(getActivity(), MyinformationActivity.class);
                startActivity(intent);
            }
        });
        my_allcollect= (LinearLayout) view.findViewById(R.id.my_allcollect);
        my_allcollect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(getActivity(), MycollectActivity.class);
                startActivity(intent);
            }
        });
        my_allexpress= (LinearLayout) view.findViewById(R.id.my_allexpress);
        my_allexpress.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(getActivity(), MyexpressActivity.class);
                startActivity(intent);
            }
        });
        my_alllose= (LinearLayout) view.findViewById(R.id.my_alllose);
        my_alllose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(getActivity(), UserLoseGoods_MainActivity.class);
                startActivity(intent);
            }
        });
        my_secondhand= (LinearLayout) view.findViewById(R.id.my_allsecondhand);
        my_secondhand.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(getActivity(), UserGoods_MainActivity.class);
                startActivity(intent);
            }
        });
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        p = BmobUser.getCurrentUser(Person.class);
        my_name.setText(p.getNickname());
        my_identification.setText(p.getUsername());
        if(!(p.getMy_image()==null||p.getMy_image().equals("")))
        {
            String url = p.getMy_image().getUrl(); // 获取地址
            DisplayImageOptions options = new DisplayImageOptions.Builder()
                    .showImageOnLoading(R.mipmap.ic_launcher)
                    .showImageOnFail(R.mipmap.ic_launcher)
                    .cacheInMemory(true)
                    .cacheOnDisk(true)
                    .bitmapConfig(Bitmap.Config.RGB_565)
                    .build();
            ImageLoader.getInstance().displayImage(url, my_iv_image, options);
        }
    }
}
